//主页下拉出现动画
$(".nav-div ul>li:nth-child(2)").hover(function () {
    $(this).children("div").slideToggle(200);
});

//商品选取数量的增加和减少
let selectAmount = 1;
$(".reduce").on("click", function () {
    if (selectAmount !== 1) {
        selectAmount -= 1;
        $(this).siblings("span").html(selectAmount);
    }
});

$(".increase").on("click", function () {
    selectAmount += 1;
    $(this).siblings("span").html(selectAmount);
});

//实现商品详情页使用数据
let imgPathTemp = localStorage.getItem("imgPath");
let goodsNameTemp = localStorage.getItem("goodsName");
let goodsPriceTemp = localStorage.getItem("goodsPrice");

$(".location-div .goods-link").html(goodsNameTemp);
$(".goods-img img").attr("src", "../" + imgPathTemp);
$(".goods-detail h2").html(goodsNameTemp);
$(".goods-detail>span").html(goodsPriceTemp);

$(".goods-show .parcel-div div").hover(function () {
    let imgPath = $(this).children("img").attr("src");
    $(".goods-show-div .goods-img img").attr("src", imgPath);
});

//实现商品颜色分类列表点击效果
let pointImg = null;
$(".goods-show-div .goods-color-sort>div").on("click", function () {
    if (pointImg !== null) {
        pointImg.removeClass("active");
        pointImg.css("border", "1px solid #fff");
    }
    $(this).css("border", "1px solid #A10000");
    $(this).addClass("active");
    pointImg = $(this);
});

//实现点击加入购物车得到商品数据并跳转到购物车页面使用数据
$(".add-gwc").on("click", function () {
    let imgPath;
    let goodsColor;
    let goodsName;
    let singlePrice;
    let selectAmount;
    let divList = $(".goods-color-sort>div");
    for (let i = 0; i < divList.length; i++) {
        if (divList[i].className === "active") {
            imgPath = $(divList[i]).children("img").attr("src");
            goodsColor = $(divList[i]).children(".color-text").children("span").html();
        }
    }
    goodsName = $(".goods-show-div .goods-detail h2").html();
    singlePrice = $(".goods-show-div .goods-detail>span").html();
    selectAmount = $(".goods-show-div .sort .select-amount").html();

    let map = [{ "gwc_imgPath": imgPath }, { "gwc_goodsColor": goodsColor }, { "gwc_goodsName": goodsName }, { "gwc_singlePrice": singlePrice }, { "gwc_selectAmount": selectAmount }];
    localStorage.setItem(goodsName + "_detail", JSON.stringify(map));
});